<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<meta charset="UTF-8">
<title><s:message code="EMPLOYEE.EDIT"></s:message></title>
</head>
<body>
<form>
<s:message code="EMPLOYEE.LASTNAME"></s:message>：<input type="text" name="lastName" value="${employee.lastName}"/><br>
<s:message code="EMPLOYEE.EMAIL"></s:message>：<input type="text" name="email" value="${employee.email}"/><br>
<s:message code="EMPLOYEE.GENDER"></s:message>：男<input type="radio" name="gender" value="男"/>  女<input type="radio" name="gender" value="女"/><br>
<input type="hidden" name="id" value="${employee.id}" id="employeeId">
<input type="submit" id="submit" value="<s:message code='SYS.SUBMIT'></s:message>">
</form>
</body>
<script>
$(function(){
    var gender = '${employee.gender}';
    if(!!gender ){
        if(gender == "男"){
            $('input:radio[name="gender"]:first').attr("checked","checked");
        }
        if(gender == "女"){
            $('input:radio[name="gender"]:last').attr("checked","checked");
        }
    }
    $("#submit").click(function(){
   	 	var array =  $("form").serializeArray();
   		var json = {};
    	for(var i=0;i<array.length;i++){
    		json[array[i].name] = array[i].value;
    	}
    	json = JSON.stringify(json);
	   	  $.ajax({
	   	        type: 'put',
	   	        url: '${pageContext.request.contextPath }/emp/update',
	   	        data: json,//必须是字符串
	   	        contentType:"application/json;charset=utf-8",
	   	        success: function(data) {
	   	        	if(data.code == 200){
	   	        		window.location.href="${pageContext.request.contextPath }/emp/list";
	   	        		return true;
	   	        	}else{
	   	        		alert(data.msg);
	   	        	}
	   	        }
	   	    }); 
   	  return false;
   })

})
</script>
</html>